<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<title>计划上报月计划表管理</title>
<meta name="decorator" content="default"/>
<link href="${ctxStatic}/bootstrap-editable/css/bootstrap-editable.css" rel="stylesheet" />
<link href="${ctxStatic}/bootstrap-table/bootstrap-table.min.css" rel="stylesheet" />
<script src="${ctxStatic}/bootstrap-editable/js/bootstrap-editable.js"></script>
<script src="${ctxStatic}/bootstrap-table/bootstrap-table.js"></script>
<script src="${ctxStatic}/bootstrap-table/locale/bootstrap-table-zh-CN.js"></script>
<script src="${ctxStatic}/bootstrap-table/extensions/editable/bootstrap-table-editable.js"></script>
<script src="${ctxStatic}/common/format/formatOrderData.js"></script>
<script type="text/javascript">
$(document).ready(function() {
	$('#tab').bootstrapTable({
		url: "${ctx}/plan/bsPlanMonthTollDetail/formView",
		queryParams: queryParams,
		clickToSelect: true,
		uniqueId: "id",
		columns: [{
			field: 'id',
			title: 'id',
			visible: false
		}, {
			field: 'vaccineid',
			title: '疫苗编码'
		}, {
			field: 'vaccname',
			title: '疫苗名称'
		}, {
			field: 'companyName',
			title: '生产企业'
		}, {
			field: 'type',
			title: '类型'
		}, {
			field: 'spec',
			title: '规格'
		}, {
			field: 'dose',
			title: '剂量'
		},{
			field: 'doseType',
			title: '剂型'
		},{
			field: 'containerType',
			title: '容器类型'
		}, {
			field: 'sellPrice',
			title: '价格（元/支、粒）'
		}, {
			field: 'planNumYear',
			title: '季度计划领取数'
		}, {
			field: 'planNumMonth',
			title: '月度计划数'
		}, {
			field: 'storenum',
			title: '库存数量'
		}, {
			field: 'storespec',
			title: '库存剂次数',
			visible: false
		}, {
			field: 'sumRealNumMonth',
			title: '统计全站点上报计划数'
		}, {
			field: 'realNumMonth',
			title: '实际领取数',
			formatter: formatVaccname
		}, {
			field: 'planNumYearRemain',
			title: '季度累计领取数'
		},{
			field: 'remarks',
			title: '备注'
		}],
		onEditableSave: function(field, row, oldValue, $el) {
			debugger;
			setTimeout(function() {
				$('#tab').find('[data-uniqueid="' + row.id + '"]').next().find('[data-name="' + field + '"]').editable('show');
			},
			200);
		}
	});
	
	//确认通过
	$("#btnAuditSun").click(function(){
		layer.confirm('确认通过?', {icon: 3, title:'提示'}, function(index){
			layer.load(2);
			$("#inputForm").attr("action", "${ctx}/plan/bsPlanMonthToll/audit?success=true");
			$("#inputForm").submit();
			layer.close(index);
		});
	});
	
	$("#btnReport").click(function(){
		var loadIndex = layer.load(2);
		var param = {
			"fromOrgCode" : $("#fromOrgCode").val(),
			"planDate" : $("#planDate").val(),
			"toOrgCode" : $("#toOrgCodeId").val()
		};
		$.post("${ctx}/plan/bsPlanMonthToll/checkPlanMonth", param, function(result){
			layer.close(loadIndex);
			if (result.success == false){
				layer.alert(result.msg, {icon: 2});
			} else if(result.success == true){
				layer.confirm('确认上报？', {icon: 3, title:'提示'}, function(index){
					layer.load(2);
					$("#inputForm").attr("action", "${ctx}/plan/bsPlanMonthToll/report?success=true");
					$("#inputForm").submit();
					layer.close(index);
				});
			}
		});
	});
	
	$("#btnExport").click(function(){
   		layer.confirm("确认要导出数据吗？", {
			btn: ['确认','取消'], //按钮
			shade: true, //不显示遮罩
			icon : 0
		}, function(index){
    		window.open("${ctx}/plan/bsPlanMonthToll/monthExport?planMonthId=${bsPlanMonthToll.id}&planDate=" + $("#planDate").val() + "&storename=${bsPlanMonthToll.fromOrgName}&storecode=${bsPlanMonthToll.fromOrgCode}","_blank");
			layer.close(index);
		}, function(){
			layer.close();
		});
   	});
});

function queryParams(params) {
    var temp = {
    	planMonthId : $("#id").val(),
        planDate : $("#planDate").val(),
        storecode : $("#fromOrgCode").val()
    };
    return temp;
};

function formatVaccname(data, row, index){
	var status = row.status;
	if(status == '1'){
		data = '<span style="color: red;"> '+data+'</span>';
	}
	return data;
};
</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/plan/bsPlanMonthToll/">月度计划列表</a></li>
		<li class="active"><a href="#">月度计划查看</a></li>
	</ul>
	<form:form id="inputForm" modelAttribute="bsPlanMonthToll" action="${ctx}/plan/bsPlanMonthToll/save" method="post" class="breadcrumb form-search">
		<form:hidden path="id" />
		<form:hidden path="planYearId" />
		<form:hidden path="planTitle" />
		<form:hidden path="planStatus" />
		<form:hidden path="fromOrgCode" />
		<form:hidden path="type" />
		<input id="tableData" name="tableData" type="hidden">
		<sys:message content="${message}" />
		<table class="table table-bordered">
			<tr>
				<th>填报单位：</th>
				<td><input readonly type="text" name="fromOrgName" id="fromOrgName" class="input-medium" value="${bsPlanMonthToll.fromOrgName}" /></td>
				<th>填报人：</th>
				<td><input type="text" name="planBy" id="planBy" readonly class="input-medium" value="${bsPlanMonthToll.planBy}" /></td>
				<th>审核单位：</th>
				<td><sys:treeselect2 id="toOrgCode" name="toOrgCode" value="${bsPlanMonthToll.toOrgCode}" labelName="toOrgName" disabled = "disabled"
						labelValue="${bsPlanMonthToll.toOrgName}" title="部门" url="/sys/office/treeData2?areaType=3" cssClass="input-medium"
						allowClear="true" notAllowSelectParent="true" /></td>
				<th>计划日期：</th>
				<td><input name="planDate" id="planDate" type="text" readonly disabled
					maxlength="20" class="input-medium Wdate "
					value="<fmt:formatDate value="${bsPlanMonthToll.planDate}" pattern="yyyy-MM"/>"
					onclick="WdatePicker({dateFmt:'yyyy-MM',isShowClear:false});" /></td>
			</tr>
		</table>
		<div>
			<button id="btnExport" class="btn btn-primary" type="button" >导出</button>
			<shiro:hasPermission name="plan:bsPlanMonthToll:edit">
				<c:if test="${bsPlanMonthToll.fromOrgCode == office.code && bsPlanMonthToll.planStatus == 3 && bsPlanMonthToll.affirmStatus == 1}">
					<button id="btnAuditSun" class="btn btn-primary" type="button">确认</button>
				</c:if>
			</shiro:hasPermission>
			<shiro:hasPermission name="plan:bsPlanYear:report">
				<c:if test="${bsPlanMonthToll.fromOrgCode == office.code && (bsPlanMonthToll.planStatus == 0 || bsPlanMonthToll.planStatus == 9)}">
					<button id="btnReport" class="btn btn-primary" type="button">上报</button>
				</c:if>
			</shiro:hasPermission>
			<button id="btnCancel" class="btn" type="button" onclick="history.go(-1)">返回</button>
		</div>
	</form:form>
	<div class="control-group table">
		<fieldset>
		    <legend>${bsPlanMonthToll.planTitle}</legend>
		</fieldset>
		<table id="tab" class="table table-bordered table-condensed">
		</table>
	</div>
</body>
</html>